/**
 *	实验四
 *	
 *	定义一个类实现银行帐户的概念，包括的变量有"帐号"和"存款余额"，包括的方法有
 *  "存款"、"取款"、"查询余额"和”显示帐号”。定义主类，创建帐户类的对象，并完成
 *	相应操作。
 */
class T2E04 
{
	public static void main(String[] args) 
	{
		BankAccount b1 = new BankAccount("yangjunjun",1000);
		System.out.println(b1.showInfo());

		b1.SaveMoney(-100);
		System.out.println(b1.showInfo());

		b1.SaveMoney(500);
		System.out.println(b1.showInfo());

		b1.withdrawMoney(3000);
		System.out.println(b1.showInfo());

		b1.withdrawMoney(800);
		System.out.println(b1.showInfo());
	}
}
class BankAccount
{
	private String accountNumber;
	private double currentMoney;
	public BankAccount() {};
	public BankAccount(String number)
	{
		this.accountNumber = number;
		this.currentMoney = 0;
	}
	public BankAccount(String number,double money)
	{
		this.accountNumber = number;
		this.currentMoney = money;
	}
	
	/* 
	 * 存钱方法，如果存入的钱小于或等于零，则存钱失败，返回false。 
	 */
	public boolean SaveMoney(double money)
	{
		if (money <= 0) 
		{
			return false;
		}
		else
		{
			this.currentMoney +=money;
			return true;
		}		
	}
	/* 
	 * 取钱方法，如果要取的钱大于账户余额，则取钱失败，返回false。 
	 */
	public boolean withdrawMoney(double money)
	{
		if (money > this.currentMoney)
		{
			return false;
		}
		else 
		{
			this.currentMoney -= money;
			return true;
		}
	}

	/**
	 *  显示帐号
	 */
	public String showAccountNumber()
	{
		return this.accountNumber;
	}
	/**
	 * 显示帐号和余额信息
	 */
	public String showInfo()
	{
		return "AccountNumber: " + this.accountNumber
			+ " currentMoney: " + this.currentMoney ;
	}
}